package com.example.lambda;

import com.example.entity.Employee;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class TestLambda {

    List<Employee> emps = Arrays.asList(
            new Employee(101, "张三", 18, 9999.99),
            new Employee(102, "李四", 59, 6666.66),
            new Employee(103, "王五", 28, 3333.33),
            new Employee(104, "赵六", 8, 7777.77),
            new Employee(105, "田七", 38, 5555.55)
    );

    @Test
    public void test1(){
        Collections.sort(emps,(e1,e2)->{
            if(e1.getAge()==e2.getAge()){
                return e1.getName().compareTo(e2.getName());
            }else {
                return Integer.compare(e1.getAge(),e2.getAge());
            }
        });

        for (Employee employee:emps){
            System.out.println(employee);
        }
    }

    @Test
    public void test2(){
        String trimStr = strHandler("\\t\\t\\t 我大尚硅谷威武   ",(str)->str.trim());
        System.out.println("去空格："+trimStr);
        String strUpper = strHandler("abcdef",(str) -> str.toUpperCase());
        System.out.println("转大写："+strUpper);
        String newStr = strHandler("我大尚硅谷威武",(str)-> str.substring(2,5));
        System.out.println("截取字符串："+newStr);
    }

    @Test
    public void test3(){
        op(100l,200l,(x,y)->x+y);
        op(100l,200l,(x,y)->x-y);
    }

    //需求：用于处理字符串
    public String strHandler(String str,MyFunction mf){

        return mf.getValue(str);
    }

    //需求：对应两个long型数值进行处理
    public void op(Long l1,Long l2,MyFunction2<Long,Long> mf){
        System.out.println(mf.getValue(l1,l2));
    }
}
